﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/include/header.jsp" %>
<%@ include file="/include/zTree.jsp" %>
<!-- 校检规则 -->
<script src="${ctx}/js/lib/jquery-ui.custom.js" type="text/javascript"></script>
</head>
<body style="background-color: white;">
	<div style="padding: 10px;">
	<div class="b_box">
		<div class="p_bar"></div>
		<div class="con_box">
	        <div class="clearfix">
	          <form id="sysAuthorityForm"  action="post">
	             <input type="hidden" name="CSRFToken" value="${csrfToken}" />
				<table class="c_table">
					<tr>
					    <td  width="100"  class="t_r"><b><i class="square"></i>权限名称：</b></td>
						<td width="170"><input type="text" class="input_txt" id="authorityName" name="authorityName" value="" data-validaterole="authorityName" data-rule="authorityName" style="width: 150px"/></td>
						
					<td class="t_r"><b><i class="square"></i>状&nbsp;&nbsp;&nbsp;&nbsp;态：</b></td>
						<td><select id="status" name="status" class="input_txt" style="width:155px;">
							<c:forEach items="${statusMap}" var="item">
								<option id="${item.key}" value="${item.key}">${item.value}</option>
							</c:forEach>
						    </select>
					     </td>
					</tr>
					<tr>
						<td width="120" class="t_r"><b><i class="square"></i>权&nbsp;限&nbsp;值：</b></td>
						<td><input type="text" id="authorityValue" class="input_txt" name="authorityValue"  data-validaterole="authorityValue" data-rule="authorityValue" style="width: 150px"/></td>
						<td class="t_r"><b><i class="square"></i>等&nbsp;&nbsp;&nbsp;&nbsp;级：</b></td>
						<td><input type="text" class="input_txt" id="grade" name="grade" value="1" data-validaterole="grade" data-rule="grade" style="width: 50px"/></td>
					</tr>
					<tr>
						<td class="t_r"><b><i class="square"></i>权限类型：</b></td>
						<td>
							<select id="authorityType" name="authorityType" class="input_txt" style="width:155px;">
								<c:forEach items="${authTypeMap}" var="item">
									<option id="${item.key}" value="${item.key}">${item.value}</option>
								</c:forEach>
							</select>
						</td>
						 <td class="t_r"><b><i class="square"></i>排&nbsp;序&nbsp;号：</b></td>
						<td colspan="3"><input type="text" class="input_txt" id="sortNo" name="sortNo" value="1" data-validaterole="sortNo" data-rule="sortNo" style="width: 50px"/></td>
					</tr>
					<tr>
					<td  class="t_r"><b><i class="square"></i>父级权限：</b></td>
						<td><input type="text" id="parentAuthorityName" disabled="disabled" class="input_txt" value="${parentSysAuthority.authorityName}" style="width: 150px"/> 
						     <input type="hidden" name="parentId" id="parentId" value="${parentSysAuthority.authorityId}"/><i class="look"></i>
						</td>
					</tr>
					<tr>
					     <td class="t_r"><b><i class="square"></i>请求地址：</b></td>
						<td colspan="3">
						        <textarea id="remark" name="action" class="input_txt" style="height:60px;width: 450px"></textarea>
						</td>
						
					</tr>
					<tr>
						<td class="t_r"><b><i class="square"></i>注&nbsp;&nbsp;&nbsp;&nbsp;释：</b></td>
						<td colspan="3"><textarea id="remark" name="remark" class="input_txt" style="height:60px;width: 450px"></textarea></td>
					</tr>
				</table>
			 </form>
			</div>
	      </div>
		
	 </div>
	<div class="action_box  m_t10 t_c"><input type="button" class="a_btn" value="保存" id="addBtn"/></div>
	</div>
	<div id="menuContent" class="menuContent" style="display:none; position: absolute;background-color: white;">
		<ul id="treeDemo" class="ztree" style="margin-top:0; width:300px;"></ul>
	</div>
	
	<script type="text/javascript">

		$(function() {
			// 验证
			seajs.use(["component/validate", "component/tip"],
			function(validate, tip) {
				var ntip = function() {
					// 定义一个提示对象
					var t = new tip({
						content: 'hello tip',
						hasArrow: true,
						arrowOption: {
							dir: "left",
							position: {
								top: 8
							}
						},
						con: "body",
						hasCloseBtn: false,
						position: {
							my: "center",
							at: "center",
							of: "#tipcon"
						},
						css: {
							width: "120"
						}
					});
					return t;
				};

				// 定义一个验证对象
				var d = new validate({
					con: "#sysAuthorityForm",
					// 验证容器
					onSubmit: "#addBtn",
					// 提交按钮
					eachInvalidField: function(res, field) { // 验证不通过的处理
						var oldTip = field.data("tip");
						var tip;
						if (typeof oldTip == "undefined") {
							tip = ntip();
							field.data("tip", tip);
						} else {
							tip = oldTip;
						}
						tip.setContent(res.message);
						tip.setPosition({
							my: "left center-15",
							at: "right+10 center",
							of: field
						});
						tip.show();
					},
					eachValidField: function(res, field) { // 验证通过则隐藏提示
						var oldTip = field.data("tip");
						var tip;
						if (typeof oldTip == "undefined") {

						} else {
							tip = oldTip;
							tip.hide();
						}
					}
				});
				// 设置拼装规则
				d.setValidateRule({authorityValue: ["isBlank"]});
				d.setValidateRule({authorityName: ["isBlank"]});
				d.setValidateRule({grade: ["isBlank"]});
				d.setValidateRule({sortNo: ["isNum"]});
				// 绑定提交按钮
				d.bind("onsubmit", function() {
					var serializedForm = $("#sysAuthorityForm").serialize();
					$.post("${ctx}/sysAuthority/add", serializedForm,
					function(result) {
						if ("succ" == result) {
							alert("操作成功");
							parent.replaceByUrl('${ctx}/sysAuthority/list');
							parent.layerClose(window.name);
			            }else {
							alert(result);
						}
					},
					"json");
				});
			});
		});
	</script>

</body>
</html>